<include file="Public/header" />
<title>企业管理</title>
</head>
<body>
<div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <input type="text" name="name" id="name" value="<{$Think.get.name}>" placeholder="企业名称" style="width:250px" class="input-text">
             <button id="search" class="btn btn-success" type="submit"><i class="Hui-iconfont"></i> 搜索</button>
            <a href="javascript:;" onclick="delAll()" class="btn btn-danger radius"><i class="Hui-iconfont"></i> 批量删除</a>
            <a class="btn btn-primary radius" data-title="添加" _href="article-add.html" onclick="add()" href="javascript:;"><i class="Hui-iconfont"></i> 添加</a>
			<a class="btn btn-primary radius" data-title="全部升级" onclick="updateAll()" href="javascript:;">全部升级</a>
			<a class="btn btn-primary radius" data-title="关联角色"  onclick="bind_role()" href="javascript:;">关联角色</a>
			<a class="btn btn-primary radius" data-title="审核" onclick="examined(1)" href="javascript:;">审核通过</a>
			<a class="btn btn-primary radius" data-title="审核" onclick="examined(2)" href="javascript:;">审核不通过</a>
        </span>
        <span class="r">共有数据：<strong><{$count}></strong> 条</span>
    </div>
    <div class="mt-20">
        <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer">
            <table class="table table-border table-bordered table-bg table-hover table-sort dataTable no-footer" id="DataTables_Table_0" role="grid" aria-describedby="DataTables_Table_0_info">
            <thead>
            <tr class="text-c" role="row">
                <th width="25" class="sorting_disabled" rowspan="1" colspan="1" aria-label="" style="width: 25px;"><input type="checkbox" name="" value=""></th>
                <th class="" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-sort="descending" aria-label="ID: 升序排列" style="width: 30px;">ID</th>
                <th class="" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="标题: 升序排列" style="width: 120px;">用户名</th>
				<th width="60" style="width: 70px;">昵称</th>
				<th width="80" class="" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" style="width: 100px;">公司名称</th>
				<th width="60" style="width: 70px;">user_code</th>
				<th width="60" style="width: 70px;">user_key</th>
				<th width="60" style="width: 70px;">审核状态</th>
                <th width="120" style="width: 120px;">添加时间</th>
				<th width="120" style="width: 120px;">角色</th>
                <th width="320" class="" rowspan="1" colspan="1" aria-label="操作" style="width: 120px;">操作</th>
            </tr>
            </thead>
            <tbody>
            <foreach name="list" item="data">
            <tr class="text-c odd" role="row">
                <td>
				<input type="checkbox" value="<{$data.id}>" name="" class="ids"></td>
                <td class="sorting_1"><{$data.id}></td>
                <td class="text-l">
				<a href="javascript:;" style="color:red" onclick="manage('<{$data.id}>')" >管理</a>
				&nbsp;&nbsp;&nbsp;&nbsp;
				<{$data.username}>
				</td>
				<td><{$data.nick_name}></td>
                <td><{$data.company}></td>
				<td><{$data.user_code}></td>
				<td><{$data.user_key}></td>
				<td width="120" style="width: 120px;">
				 <if condition="$data.status eq 0">
				 未审核
				 </if>
				 <if condition="$data.status eq 1">
				 审核通过
				 </if>
				 <if condition="$data.status eq 2">
				 审核未通过
				 </if>
				 </td>
                <td width="120" style="width: 120px;"><{$data.created_at}></td>
				<td width="120" style="width: 120px;"><{$data.department_name}></td>
                <td class="f-14 td-manage">
					<a href="javascript:;" onclick="warehouse('<{$data.id}>')" >仓库</a>
					<a href="javascript:;" onclick="config('<{$data.id}>')" class="btn btn-success radius">基本配置</a>
                    <a style="text-decoration:none" class="ml-5" onclick="edit('<{$data.id}>')" href="javascript:;" title="编辑"><i class="Hui-iconfont"></i></a>
                    <a style="text-decoration:none" class="ml-5" onclick="del('<{$data.id}>')" href="javascript:;" title="删除"><i class="Hui-iconfont"></i></a>
                </td>
            </tr>
            </foreach>
            </tbody>
        </table>
            <div class="page">
                <{$page}>
            </div>
    </div>
</div>
<include file="Public/footer" />
<include file="Public/footer_js" />
<script>
	//扣月租
	function month_rent(){
			var option = $(".ids");
			var checked_counts=0;
			var check_val = [];
            for(var i=0;i<option.length;i++){
				if(option[i].checked){
					checked_counts++;
					check_val.push(option[i].value);
				}
			}
			if(checked_counts!=1){
				layer.msg('一次只能选中一个');
				return false;
			}else{
				$.post('__MODULE__/Member/month_rentss',{
					id:check_val[0],
				},function (msg){
					layer.msg(msg.message);
					if(msg.status==1){
						setTimeout(function (){
							location.reload();
						},800);
					}
				},'json');
			}
	}

	function examined(val){
			var option = $(".ids");
			var checked_counts=0;
			var check_val = [];
            for(var i=0;i<option.length;i++){
				if(option[i].checked){
					checked_counts++;
					check_val.push(option[i].value);
				}
			}
			<!-- alert(check_val); -->
			if(checked_counts==0){
				layer.msg('至少选中一个');
				return false;
			}else{
				 $.post('__CONTROLLER__/examined',{
					ids:check_val,
					val:val
				},function(msg){
					layer.msg(msg.data,function(){
						location.reload();
					});
				},'json');
			}
	}
	function bind_feerule(){
			var option = $(".ids");
			var checked_counts=0;
			var check_val = [];
			for(var i=0;i<option.length;i++){
				if(option[i].checked){
					checked_counts++;
					check_val.push(option[i].value);
				}
			}
			if(checked_counts==0){
				layer.msg('至少选中一个');
				return false;
			}else{
				var index=layer.open({
				  title: '选择费用规则',
				  type: 2,
				  area: ['320px', '280px'], //宽高
				  content: '__MODULE__/Company/bind_feerule/ids/'+check_val //iframe的url
				});
				
			}
	}
	function bind_member(){
			var option = $(".ids");
			var checked_counts=0;
			var check_val = [];
            for(var i=0;i<option.length;i++){
				if(option[i].checked){
					checked_counts++;
					check_val.push(option[i].value);
				}
			}
			if(checked_counts==0){
				layer.msg('至少选中一个');
				return false;
			}else{
				var index=layer.open({
				  title: '选择会员',
				  type: 2,
				  area: ['300px', '280px'], //宽高
				  content: '__MODULE__/Company/bind_member/ids/'+check_val //iframe的url
				});
				
			}
    }
	function bind_erp(){
			var option = $(".ids");
			var checked_counts=0;
			var check_val = [];
            for(var i=0;i<option.length;i++){
				if(option[i].checked){
					checked_counts++;
					check_val.push(option[i].value);
				}
			}
			if(checked_counts==0){
				layer.msg('至少选中一个');
				return false;
			}else{
				var index=layer.open({
				  title: '选择ERP',
				  type: 2,
				  area: ['300px', '280px'], //宽高
				  content: '__MODULE__/Company/bind_erp/ids/'+check_val //iframe的url
				});
			}
    }
	function bind_role(){
			var option = $(".ids");
			var checked_counts=0;
			var check_val = [];
            for(var i=0;i<option.length;i++){
				if(option[i].checked){
					checked_counts++;
					check_val.push(option[i].value);
				}
			}
			if(checked_counts==0){
				layer.msg('至少选中一个');
				return false;
			}else{
				var index=layer.open({
				  title: '选择角色组',
				  type: 2,
				  area: ['300px', '280px'], //宽高
				  content: '__MODULE__/Company/bind_role/ids/'+check_val //iframe的url
				});
				
			}
    }
    $("#search").click(function (){
        location.href="__CONTROLLER__/index/name/"+$("#name").val();
    });
	function manage(erp_id){
        index_url="<{:U('Company/index/index')}>";
		url="<{:U('Company/Reg/admin_manage')}>";
		$.ajax({
			url:url,
			data:{erp_id:erp_id},
			type:"post",
			success:function(data){
				console.log(data);
				if(data.status){
					layer.msg("登录成功，正在跳转",function(){
						window.open(index_url);
					});
				}else{
					layer.msg(data.message);
				}
			}
		})
    }
    function add(){
        var index=layer.open({
            type: 2,
            title: '企业添加',
            shadeClose: true,
            shade: 0.5,
            area: ['400px', '400px'],
            content: '__MODULE__/Company/add' //iframe的url
        });
    }
	//清空数据
	function truncateAll(id){
		<!-- alert(id); -->
		layer.confirm('点击确定将清空此erp数据库数据', {
		  btn: ['确定','取消']//按钮
		}, function(index){
			layer.close(index);
			layer.open({
			  type: 2,
			  title: '清空数据',
			  shadeClose: true,
			  shade: 0.8,
			  area: ['380px', '90%'],
			  content: "__MODULE__/Company/truncateAll/id/"+id //iframe的url
			});
		});
	}
	//数据升级
	function updateAll(_this){
		layer.confirm('点击确定将升级所有erp数据库', {
		  btn: ['确定','取消'] //按钮
		}, function(index){
			layer.close(index);
			layer.open({
			  type: 2,
			  title: '数据导入',
			  shadeClose: true,
			  shade: 0.8,
			  area: ['380px', '90%'],
			  content: '__MODULE__/Company/updateAll' //iframe的url
			});
		});
	}
    function edit(id){
        var index=layer.open({
            type: 2,
            title: '企业修改',
            shadeClose: true,
            shade: 0.5,
            area: ['400px', '400px'],
            content: '__MODULE__/Company/edit/id/'+id //iframe的url
        });
    }
	function ems(id){
        var index=layer.open({
            type: 2,
            title: '订单列表',
            shadeClose: true,
            shade: 0.5,
            area: ['1200px', '600px'],
            content: '__MODULE__/Company/ems/user_id/'+id //iframe的url
        });
    }
	function config(id){
        var index=layer.open({
            type: 2,
            title: '基本配置',
            shadeClose: true,
            shade: 0.5,
            area: ['800px', '600px'],
            content: '__MODULE__/Company/config/user_id/'+id //iframe的url
        });
    }
    function warehouse(id){
        var index=layer.open({
            type: 2,
            title: '仓库管理',
            shadeClose: true,
            shade: 0.8,
            area: ['380px', '90%'],
            content: '__MODULE__/Company/warehouse/id/'+id //iframe的url
        });
        layer.full(index);
    }
    function delAll(){
        var all_ipt=$("#DataTables_Table_0_wrapper input[type=checkbox]:checked");
        var group_id='';
        for(var i=0;i<all_ipt.length;i++){
            if(all_ipt.eq(i).val()!==''){
                group_id+='@'+all_ipt.eq(i).val();
            }
        }
        if(group_id.substring(1)==''){
            layer.msg('请勾选要删除的信息');
            return false;
        }
        del(group_id.substring(1));
    }
	function del(id){
		layer.confirm('删除用户将删除数据库，不能恢复！请谨慎操作！',function(){
			$.get('__MODULE__/Company/del',{
				 id:id,
			 },function (msg){
				 layer.msg(msg.data);
				setTimeout(function (){
					location.reload();
				},800);
			 },'json');
		});
     }
</script>
</body>
</html>